<?php

namespace app\merchant\model;

use think\Model;

/**
 * 资产
 */
class TpAssets extends Model
{
    //设置当前模型对应的完整数据表名称
    protected $table = 'tp_assets';
    
    //还款方式
    CONST REPAYMENT_TYPE_EXPIRY = 1; //到期还本息
    CONST REPAYMENT_TYPE_MONTH = 2; //按月付息，到期还本
    CONST REPAYMENT_TYPE_SEASON = 3; //按季付息，到期还本
    CONST REPAYMENT_TYPE_QUEAL = 4; //等额本息
    
    //资产类型
    CONST TYPE_CAR = 1; //车贷
    CONST TYPE_CONSUME = 2; //消费贷
    CONST TYPE_ENTERPRISE = 3; //企业贷
    
    //状态
    CONST STATUS_BACK = 1; //驳回
    CONST STATUS_CHECK = 2; //待审核
    CONST STATUS_TO_BE_RAISE = 3; //审核通过
    
    /**
     * 获取还款方式列表
     * @return type
     */
    public static function getRepaymentTypeList()
    {
        $list = [
            self::REPAYMENT_TYPE_EXPIRY => '到期还本息',
            self::REPAYMENT_TYPE_MONTH => '按月付息，到期还本',
            self::REPAYMENT_TYPE_SEASON => '按季付息，到期还本',
            self::REPAYMENT_TYPE_QUEAL => '等额本息'
        ];
        
        return $list;
    }
    
    /**
     * 根据代码获取还款方式名称
     * @param type $repayment_type 还款方式代码
     * @return type 还款方式名称
     */
    public static function getRepaymentTypeName($repayment_type)
    {
        $list = [
            self::REPAYMENT_TYPE_EXPIRY => '到期还本息',
            self::REPAYMENT_TYPE_MONTH => '按月付息，到期还本',
            self::REPAYMENT_TYPE_SEASON => '按季付息，到期还本',
            self::REPAYMENT_TYPE_QUEAL => '等额本息'
        ];
        
        return isset($list[$repayment_type]) ? $list[$repayment_type] : '未知还款方式：' . $repayment_type;
    }
    
    /**
     * 获取资产类型类型名称
     * @param type $type 资产类型代码
     * @return type 资产类型名称
     */
    public static function getTypeName($type)
    {
        $list = [
            self::TYPE_CAR => '车贷',
            self::TYPE_CONSUME => '消费贷',
            self::TYPE_ENTERPRISE => '企业贷'
        ];
        
        return isset($list[$type]) ? $list[$type] : '未知资产类型：' . $type;
    }
    
    /**
     * 获取状态列表
     * @return type
     */
    public static function getStatusList()
    {
        $list = [
            self::STATUS_BACK => '驳回',
            self::STATUS_CHECK => '待审核',
            self::STATUS_TO_BE_RAISE => '审核通过',
        ];
        
        return $list;
    }
    
    /**
     * 根据代码获取状态名称
     * @param type $status 状态代码
     * @return type 状态名称
     */
    public static function getStatusName($status)
    {
        $list = [
            self::STATUS_BACK => '驳回',
            self::STATUS_CHECK => '待审核',
            self::STATUS_TO_BE_RAISE => '审核通过',
        ];
        
        return isset($list[$status]) ? $list[$status] : '未知状态：' . $status;
    }
}
